package com.xiangban.xiangbanmall.controller;

import com.xiangban.xiangbanmall.aop.Permission;
import com.xiangban.xiangbanmall.model.TUserRelation;
import com.xiangban.xiangbanmall.model.res.ApiResult;
import com.xiangban.xiangbanmall.service.UserRelationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Mr. MaYaYun
 * @Data 2021/11/2 15:40
 */
@RestController
@RequestMapping("/api/mall/user_relation")
@Api(tags = "家人管理")
public class UserRelationController {

    @Autowired
    private UserRelationService userRelationService;

    @RequestMapping("/get_relation")
    @ApiOperation("亲属关系列表")
    @Permission
    public ApiResult<Object> getRelation(){
        return ApiResult.newSuccess(userRelationService.getRelation());
    }

    @RequestMapping("/get_user_relation")
    @ApiOperation("家人列表")
    @Permission
    public ApiResult<Object> getUserRelation(){
        return ApiResult.newSuccess(userRelationService.getUserRelation());
    }

    @RequestMapping("/add_user_relation")
    @ApiOperation("绑定家人")
    @Permission
    public ApiResult<Object> addUserRelation(@RequestBody TUserRelation tUserRelation) throws Exception {
        userRelationService.addUserRelation(tUserRelation);
        return ApiResult.newSuccess();
    }

    @RequestMapping("/delete_user_relation")
    @ApiOperation("删除绑定")
    @Permission
    public ApiResult<Object> deleteUserRelation(@RequestBody TUserRelation tUserRelation){
        userRelationService.deleteUserRelation(tUserRelation);
        return ApiResult.newSuccess();
    }

}
